<?php namespace Phpcmf\Controllers\Member;

/**
 * 二次开发时可以修改本文件，不影响升级覆盖
 */

class Lishi extends \Phpcmf\Home\Module
{
	public function __construct() {
        parent::__construct();
    }

	public function index() {
		//判断是get
		
			//get 参数
			$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
			$cid = (int)\Phpcmf\Service::L('input')->get('cid'); // 圈子id
			$shuju_data = \Phpcmf\Service::M()->db->table('1_quan_form_quantie')->where('id', $id)->where('status', 1)->get()->getRowArray();
			//标题
			if($shuju_data['title']){
				$zantitle = $shuju_data['title'];
			} else {
				$zantitle = dr_strcut(dr_clearhtml($shuju_data['neirong']), 20);
			}
			
			
			
			// 判断 
			$lishi_data = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_lishi')->where('tieid', $id)->where('uid', $this->uid)->countAllResults();
			if($lishi_data){
				// 已经添加了 那么就更新
				//\Phpcmf\Service::M()->db->table('1_quan_form_quantie_lishi')->where('tieid', $id)->where('uid', $this->uid)->up();
				//$lishi_tongji = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_lishi')->where('tieid', $id)->countAllResults();
				/*$data = [
					'code' => 0,
					'data' => $lishi_tongji,
					'uid'=> $this->uid,
				];*/
			} else {
				// 插入数据
				$insert_data = [
					'tieid' => $id,
					'uid' => $this->uid,
					'shenhe' => 1,
					'tianjiashijian' => time(),
				];
				$insert_id = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_lishi')->insert($insert_data);
				if($insert_id){
					$lishi_tongji = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_lishi')->where('tieid', $id)->countAllResults();
					$data = [
						'code' => 1,
						'data' => $lishi_tongji,
						'uid'=> $this->uid,
					];
					
				}
			}
			
			$this->_json('1', '提交历史');

	}
	public function  shoucang_panduan() {
		//get 参数
		$id = (int)\Phpcmf\Service::L('input')->get('id'); //帖子id
		
		$shoucang_data = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_shoucang')->where('tieid', $id)->where('uid', $this->uid)->countAllResults();
		$shoucang_tongji = \Phpcmf\Service::M()->db->table('1_quan_form_quantie_shoucang')->where('tieid', $id)->countAllResults();
		if($shoucang_data){
			$data = [
				'code' => 1,
				'data' => $shoucang_tongji,
				'uid'=> $this->uid,

			];

			
			$this->_json('1', '已收藏',$data);
		} else {
			$data = [
				'code' => 0,
				'data' => $shoucang_tongji,
				'uid'=> $this->uid,
			];
			$this->_json('0', '未收藏',$data);
		}
		
		
	}

}
